package config

import (
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
	"strings"
)

type (
	Config struct {
		rest.RestConf
		PropertyRpc zrpc.RpcClientConf
		Regexp      Regexp
		/*Redis       struct {
			Host string
			Type string `json:",default=node,options=node|cluster"`
			Pass string `json:",optional"`
			Tls  bool   `json:",optional"`
		}*/
		Auth struct {
			AccessSecret string
			AccessExpire int64
		}
		//KqPusherConf kq.KqConf
	}

	Regexp struct {
		Dept Regexps
		Svc  Regexps
		Cost Regexps
		Code string
	}
	Regexps []string
)

func (re Regexps) GetSerial(index int, handle func(*strings.Builder, string)) string {
	if index <= 0 || index > len(re) {
		return ""
	}
	var regexp strings.Builder
	for i := 0; i < index; i++ {
		handle(&regexp, re[i])
	}
	str := regexp.String()
	if strings.HasSuffix(str, ".") {
		regexp.Reset()
		regexp.WriteString(str[:len(str)-1])
	}
	regexp.WriteString("$")
	return regexp.String()
}
